//贷款id,客户id
var loanId,clientId;
//初始化审核表单
var initForm = function(){
	 //初始化审核表单
     $('#auditForm').form({
		url :'sys/LoanAudit/addOrUpdate',
		onBeforeLoad : function(param){
			$.messager.progress();
		},
		onLoadSuccess : function(data) {
			$.messager.progress("close");
			var editor_a = new baidu.editor.ui.Editor();
    	    editor_a.render('auditBase',{ toolbars: [
    	                      		               ['fullscreen', 'source', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontborder', 'backcolor', 'fontsize', 'fontfamily', 'justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', 'link', 'unlink', 'emotion', 'help']
    	                      			          ]});
    	    editor_a.ready(function() {
    	        editor_a.setContent(data.auditBase);  //赋值给UEditor
    	    });
    	    
    	    editor_a = new baidu.editor.ui.Editor();
    	    editor_a.render('auditWork');
    	    editor_a.ready(function() {
    	        editor_a.setContent(data.auditWork);  //赋值给UEditor
    	    });
    	    
    	    editor_a = new baidu.editor.ui.Editor();
    	    editor_a.render('auditCompany');
    	    editor_a.ready(function() {
    	        editor_a.setContent(data.auditCompany);  //赋值给UEditor
    	    });
    	    
    	    editor_a = new baidu.editor.ui.Editor();
    	    editor_a.render('auditHouse');
    	    editor_a.ready(function() {
    	        editor_a.setContent(data.auditHouse);  //赋值给UEditor
    	    });
    	    
    	    editor_a = new baidu.editor.ui.Editor();
    	    editor_a.render('auditCredit');
    	    editor_a.ready(function() {
    	        editor_a.setContent(data.auditCredit);  //赋值给UEditor
    	    });
    	    
    	    editor_a = new baidu.editor.ui.Editor();
    	    editor_a.render('auditSafeMeasure');
    	    editor_a.ready(function() {
    	        editor_a.setContent(data.auditSafeMeasure);  //赋值给UEditor
    	    });
    	    
    	    editor_a = new baidu.editor.ui.Editor();
    	    editor_a.render('auditOther');
    	    editor_a.ready(function() {
    	        editor_a.setContent(data.auditOther);  //赋值给UEditor
    	    });

		},
		onLoadError : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
			$.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
		},
		onSubmit : function(param) {
			if (!$(this).form("validate")) {
				$.dialog.alert("提交的选项中,有错误内容,请检查");
				return false;
			}
			$.messager.progress();
		},
		success : function(data) {	
			$.messager.progress("close");
			var data = eval('(' + data + ')');
			if(!!!data){
				$.dialog.alert("未知异常");
				return false;
			}
			if(data.state!=200){
				$.dialog.alert(jd.message);
				return false;
			}
			$.dialog({
				icon: 'success.gif',
				title: '提示',
			    content: '操作成功！',
			    ok: function(){
			        this.close();
			    }
			});
			$("#auditId").val(data.id);
		}
	});
     //初始化社保表单
     $('#insureForm').form({
    	 url :'sys/LoanInsure/addOrUpdate',
    	 onBeforeLoad : function(param){
    		 $.messager.progress();
    	 },
    	 onLoadSuccess : function(data) {
    		 
    		 $.messager.progress("close");
    	 },
    	 onLoadError : function(data) {
    		 //加载完成之后才构建
    		 $.messager.progress("close");
    		 $.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
    	 },
    	 onSubmit : function(param) {
    		 if (!$(this).form("validate")) {
    			 $.dialog.alert("提交的选项中,有错误内容,请检查");
    			 return false;
    		 }
    		 $.messager.progress();
    	 },
    	 success : function(data) {	
    		 $.messager.progress("close");
    		 var data = eval('(' + data + ')');
    		 if(!!!data){
    			 $.dialog.alert("未知异常");
    			 return false;
    		 }
    		 if(data.state!=200){
    			 $.dialog.alert(jd.message);
    			 return false;
    		 }
    		 $.dialog({
 				icon: 'success.gif',
 				title: '提示',
 			    content: '操作成功！',
 			    ok: function(){
 			        this.close();
 			    }
 			});
    		 $("#insureId").val(data.id);
    	 }
     });
     //初始化电话调查表单
     $('#linkForm').form({
    	 url :'sys/LoanLink/addOrUpdate',
    	 onBeforeLoad : function(param){
    		 $.messager.progress();
    	 },
    	 onLoadSuccess : function(data) {
    		 
    		 $.messager.progress("close");
    	 },
    	 onLoadError : function(data) {
    		 //加载完成之后才构建
    		 $.messager.progress("close");
    		 $.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
    	 },
    	 onSubmit : function(param) {
    		 if (!$(this).form("validate")) {
    			 $.dialog.alert("提交的选项中,有错误内容,请检查");
    			 return false;
    		 }
    		 $.messager.progress();
    	 },
    	 success : function(data) {	
    		 $.messager.progress("close");
    		 var data = eval('(' + data + ')');
    		 if(!!!data){
    			 $.dialog.alert("未知异常");
    			 return false;
    		 }
    		 if(data.state!=200){
    			 $.dialog.alert(jd.message);
    			 return false;
    		 }
    		 $.dialog({
  				icon: 'success.gif',
  				title: '提示',
  			    content: '操作成功！',
  			    ok: function(){
  			        this.close();
  			    }
  			});
    		 $("#linkId").val(data.id);
    		 $('#linkTable').dataTable().fnDraw();
    	 }
     });
     
   //初始化信用调查表单
     $('#creditForm').form({
    	 url :'sys/LoanCreditLog/addOrUpdate',
    	 onBeforeLoad : function(param){
    		 $.messager.progress();
    	 },
    	 onLoadSuccess : function(data) {
    		 
    		 $.messager.progress("close");
    	 },
    	 onLoadError : function(data) {
    		 //加载完成之后才构建
    		 $.messager.progress("close");
    		 $.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
    	 },
    	 onSubmit : function(param) {
    		 if (!$(this).form("validate")) {
    			 $.dialog.alert("提交的选项中,有错误内容,请检查");
    			 return false;
    		 }
    		 $.messager.progress();
    	 },
    	 success : function(data) {	
    		 $.messager.progress("close");
    		 var data = eval('(' + data + ')');
    		 if(!!!data){
    			 $.dialog.alert("未知异常");
    			 return false;
    		 }
    		 if(data.state!=200){
    			 $.dialog.alert(jd.message);
    			 return false;
    		 }
    		 $.dialog({
   				icon: 'success.gif',
   				title: '提示',
   			    content: '操作成功！',
   			    ok: function(){
   			        this.close();
   			    }
   			});
    		 $("#creditId").val(data.id);
    		 $('#creditTable').dataTable().fnDraw();
    	 }
     });
     
   //初始化建议额度表单
     $('#sugForm').form({
    	 url :'sys/LoanSug/addOrUpdate',
    	 onBeforeLoad : function(param){
    		 $.messager.progress();
    	 },
    	 onLoadSuccess : function(data) {
    		 
    		 $.messager.progress("close");
    	 },
    	 onLoadError : function(data) {
    		 //加载完成之后才构建
    		 $.messager.progress("close");
    		 $.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
    	 },
    	 onSubmit : function(param) {
    		 if (!$(this).form("validate")) {
    			 $.dialog.alert("提交的选项中,有错误内容,请检查");
    			 return false;
    		 }
    		 $.messager.progress();
    	 },
    	 success : function(data) {	
    		 $.messager.progress("close");
    		 var data = eval('(' + data + ')');
    		 if(!!!data){
    			 $.dialog.alert("未知异常");
    			 return false;
    		 }
    		 if(data.state!=200){
    			 $.dialog.alert(jd.message);
    			 return false;
    		 }
    		 $("#sugId").val(data.id);
    		 submitAudit();
    	 }
     });
     
     $('#inspectForm').form({
 		url :'sys/SysAccessoryExt/upload',
 		onBeforeLoad : function(param){
 			$.messager.progress();
 		},
 		onLoadSuccess : function(data) {
 			//加载完成之后才构建
 			$.messager.progress("close");
 		},
 		onLoadError : function(data) {
 			//加载完成之后才构建
 			$.messager.progress("close");
 			$.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
 		},
 		onSubmit : function(param) {
 			if (!$(this).form("validate")) {
 				$.dialog.alert("提交的选项中,有错误内容,请检查");
 				return false;
 			}
 			$.messager.progress();
 		},
 		success : function(data) {	
 			$.messager.progress("close");
 			var jd = eval('(' + data + ')');
 			if(!!!jd){
 				$.dialog.alert("未知异常");
 				return false;
 			}
 			if(jd.state!=200){
 				$.dialog.alert(jd.message);
 				return false;
 			}
 			$('#inspectTable').dataTable().fnDraw();
 			
 		}
 	});
     
   //初始化转考察表单
     $('#_inspect_detail').form({
 		url :'sys/LoanInspect/addOrUpdate',
 		onBeforeLoad : function(param){
 			$.messager.progress();
 		},
 		onLoadSuccess : function(data) {
 			
 			$.messager.progress("close");
 		},
 		onLoadError : function(data) {
 			//加载完成之后才构建
 			$.messager.progress("close");
 			$.dialog.alert("加载内容失败,请重新刷新页面/联系管理员");
 		},
 		onSubmit : function(param) {
 			if (!$(this).form("validate")) {
 				$.dialog.alert("提交的选项中,有错误内容,请检查");
 				return false;
 			}
 			$.messager.progress();
 		},
 		success : function(data) {	
 			$.messager.progress("close");
 			var data = eval('(' + data + ')');
 			if(!!!data){
 				$.dialog.alert("未知异常");
 				return false;
 			}
 			if(data.state!=200){
 				$.dialog.alert(jd.message);
 				return false;
 			}
 			$.ajax({
// 		       	url:'sys/Loan/addOrUpdate',
	 		   	url:'sys/LoanExt/submitStatus',
 		    	data:{id:loanId,loanStatus:3,loanInspect:$("input[name='inspectUserId']").val(),loanInspectName:$("input[name='inspectUserName']").val(),inspectStatus:0,returnStatus:0},
 		    	type:'post',
 		    	dataType:'json',
 		    	success:function(result){
 		    	        if(result.state == "200"){
 		    	        	$.dialog({
 		    					icon: 'success.gif',
 		    					title: '提示',
 		    				    content: '转考察成功！',
 		    				    ok: function(){
 		    				    	location.href="jsp/loan/auditLoanList.jsp";
 		    				    }
 		    				});
 		    	        }else{
 		    	        	$.dialog.alert('转考察失败！');
 		    	        }
 		    		}
 		        });
 		}
 	});
};

//初始化审核数据
var initFormData = function(){
	if(_is_not_empty(loanId)){
		$('#auditForm').form('load', 'sys/LoanAudit/find?loanId=' + loanId);
		$('#insureForm').form('load', 'sys/LoanInsure/find?loanId=' + loanId);
		$('#sugForm').form('load', 'sys/LoanSug/find?loanId=' + loanId);
		$('#_inspect_detail').form('load', 'sys/LoanInspect/find?loanId=' + loanId);
		
	}else{
		UE.getEditor('auditBase');
		UE.getEditor('auditWork');
		UE.getEditor('auditCompany');
		UE.getEditor('auditHouse');
		UE.getEditor('auditCredit');
		UE.getEditor('auditSafeMeasure');
		UE.getEditor('auditOther');
	}
};

//初始化列表
var initDataTable = function(){
	$('#linkTable').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        "aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 5, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : true, //是否显示（应用）分页器
        "bInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : true, //是否启动各个字段的排序功能
        "aaSorting" : [[0, "ASC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
        "sScrollX": "100%",
		"sScrollXInner": 1650,
        "sPaginationType": "full_numbers",
	    "sAjaxSource":"sys/LoanLink/list",
        "fnServerData":retrieveData,  //自定义数据获取函数
		"aoColumns" : [ {
			"mDataProp" : "id",
			"sTitle" : "序号",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},{
			"mDataProp" : "",
			"sTitle" : "操作",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		      var id = row.id,loanStatus=row.loanStatus;
		      var parseStr = '<a href="javascript:updateLinkInfo('+id+');" class="tablelink">编辑</a>&nbsp;&nbsp;';
		      parseStr += '<a href="javascript:dropLinkInfo('+id+');" class="tablelink">删除</a>&nbsp;';
		      return parseStr;
		    }
			
		}, {
			"mDataProp" : "linkName",
			"sTitle" : "联系人",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "linkRelation",
			"sTitle" : "关系",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				  if(!data){
					  return "";
				  }
			      return top.SYS_BASE_DATA['Loan_Link_Relation_Type_Code'][data];
				}
		}, {
			"mDataProp" : "linkSource",
			"sTitle" : "电话来源",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				  if(!data){
					  return "";
				  }
			      return top.SYS_BASE_DATA['Loan_Link_Source_Code'][data];
				}
		}, {
			"mDataProp" : "linkTel",
			"sTitle" : "电话号码",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "linkTime",
			"sTitle" : "拨打时间",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var value = '';
				if(_is_empty(data)){
					value = '';
				}else{
					value = new Date(data).format('yyyy-MM-dd');
				}
				
	            return value;
		     }
		}, {
			"mDataProp" : "linkCallStatus",
			"sTitle" : "通话情况",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				  if(!data){
					  return "";
				  }
			      return top.SYS_BASE_DATA['Loan_Link_Call_Status_Code'][data];
				}
			
		},{
			"mDataProp" : "linkCallRemark",
			"sTitle" : "通话备注",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
			
		}
		
		],
		"oLanguage": {
            "sUrl":"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        }
        
	});
	
	//初始化信用列表
	$('#creditTable').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        "aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 5, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : true, //是否显示（应用）分页器
        "bInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : true, //是否启动各个字段的排序功能
        "aaSorting" : [[0, "ASC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
        "sScrollX": "100%",
		"sScrollXInner": 1650,
	    "sAjaxSource":"sys/LoanCreditLog/list",
        "fnServerData":creRetrieveData,  //自定义数据获取函数
		"aoColumns" : [ {
			"mDataProp" : "id",
			"sTitle" : "序号",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		},
		  {
			"mDataProp" : "",
			"sTitle" : "操作",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		      var id = row.id,loanStatus=row.loanStatus;
		      var parseStr = '<a href="javascript:updateCreditInfo('+id+');" class="tablelink">编辑</a>&nbsp;&nbsp;';
		      parseStr += '<a href="javascript:dropCreditInfo('+id+');" class="tablelink">删除</a>&nbsp;';
		      return parseStr;
		    }
			
		} ,{
			"mDataProp" : "loanType",
			"sTitle" : "贷款方式",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				  if(!data){
					  return "";
				  }
			      return top.SYS_BASE_DATA['Loan_Credit_Type_Code'][data];
				}
		}, {
			"mDataProp" : "loanAccount",
			"sTitle" : "贷款方",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "loanAmount",
			"sTitle" : "贷款总额（元）",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "loanBalance",
			"sTitle" : "余额（元）",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "loanDeadline",
			"sTitle" : "期限（月）",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "loanPayMonth",
			"sTitle" : "月供款额（元）",
			"sDefaultContent" : "",
			"sClass" : "center"
			
		},  {
			"mDataProp" : "loanStartDate",
			"sTitle" : "放款日期",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var value = '';
				if(_is_empty(data)){
					value = '';
				}else{
					value = new Date(data).format('yyyy-MM-dd');
				}
				
	            return value;
		     }
			
		},{
			"mDataProp" : "loanEndDate",
			"sTitle" : "到期日期",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
				var value = '';
				if(_is_empty(data)){
					value = '';
				}else{
					value = new Date(data).format('yyyy-MM-dd');
				}
				
	            return value;
		     }
		},{
			"mDataProp" : "loanDefaultAmount",
			"sTitle" : "拖欠金额（元）",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center"
		}
		
		],
		"oLanguage": {
            "sUrl":"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        }
        
	});
	
	$('#inspectTable').dataTable({
		"bProcessing" : true, //DataTables载入数据时，是否显示‘进度’提示
        "bServerSide" : true, //是否启动服务器端数据导入
        "bStateSave" : false, //是否打开客户端状态记录功能,此功能在ajax刷新纪录的时候不会将个性化设定回复为初始化状态
        "bJQueryUI" : true, //是否使用 jQury的UI theme
        "aLengthMenu" : [5, 10, 15], //更改显示记录数选项
        "iDisplayLength" : 5, //默认显示的记录数
        "bAutoWidth" : true, //是否自适应宽度 update\
        "bScrollCollapse" : false, //是否开启DataTables的高度自适应，当数据条数不够分页数据条数的时候，插件高度是否随数据条数而改变
        "bPaginate" : true, //是否显示（应用）分页器
        "bInfo" : true, //是否显示页脚信息，DataTables插件左下角显示记录数
        "sPaginationType" : "full_numbers", //详细分页组，可以支持直接跳转到某页
        "bSort" : true, //是否启动各个字段的排序功能
        "aaSorting" : [[1, "DESC"]], //默认的排序方式，第3列，升序排列
        "bFilter" : false, //是否启动过滤、搜索功能
        "sScrollX": "100%",
		"sScrollXInner": 1650,
        "sPaginationType": "full_numbers",
	    "sAjaxSource":'sys/SysAccessory/list',
        "fnServerData":inspectRetrieveData,  //自定义数据获取函数
		"aoColumns" : [ {
			"mDataProp" : "uid",
			"sTitle" : "操作",
			"bSortable": false,
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		      return  ( '<a href="javascript:down_load('+row.id+');" class="tablelink">'+'下载'+'</a>'+'&nbsp;&nbsp;'+'<a href="javascript:del_default('+row.id+');" class="tablelink">'+'删除'+'</a>');
		    }
			
		}, {
			"mDataProp" : "accessoryTheme",
			"sTitle" : "主题",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "accessoryName",
			"sTitle" : "文件名",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		        return '<a href="javascript:down_load('+row.id+');">'+data+'</a>';
		     }
		}, {
			"mDataProp" : "accessoryClass",
			"sTitle" : "附件类型",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		        return SYS_BASE_DATA['Accessory_Class_Audit_Code'][data]||'';
		     }
		}, {
			"mDataProp" : "addUser",
			"sTitle" : "上传人",
			"sDefaultContent" : "",
			"sClass" : "center",
			"mRender": function (data, display, row) {
		        return data||'ADMIN';
		     }
		}, {
			"mDataProp" : "addTime",
			"sTitle" : "上传时间",
			"sDefaultContent" : "",
			"sClass" : "center"
		}, {
			"mDataProp" : "accessoryRemark",
			"sTitle" : "备注",
			"sDefaultContent" : "",
			"sClass" : "center"
			
		}
		  
		],
		"oLanguage": {
            "sUrl":"static_resources/language/lang-cn.txt" //这个是国际化，也就是汉化的各种文字数据源，写对url就行了
        }
        
	});
};

//自定义loan_link数据获取函数
var retrieveData = function ( sSource, aoData, fnCallback ) {
		aoData.push({name:"beanProxy[loanId]",value:loanId});
		aoData.push({name:"v2hldghlcib0agugzgf0ysbhy2nlc3m",value:1});
	        $.ajax( {
	                type: "POST", 
	                url: sSource, 
	                cache : false,
	                dataType : "json",
	                data : aoData, 
	                success: function(resp) {
	                	if(resp && resp.state == 200){
	                		fnCallback(resp.datagrid);
	                		return false;
	                	}
	                	fnCallback(null);
	            }
	        });
};

//自定义loan_creditor_log数据获取函数
var creRetrieveData = function ( sSource, aoData, fnCallback ) {
		aoData.push({name:"beanProxy[loanId]",value:loanId});
		aoData.push({name:'v2hldghlcib0agugzgf0ysbhy2nlc3m',value:1});
	        $.ajax( {
	                type: "POST", 
	                url: sSource, 
	                cache : false,
	                dataType : "json",
	                data : aoData, 
	                success: function(resp) {
	                	if(resp && resp.state == 200){
	                		fnCallback(resp.datagrid);
	                		return false;
	                	}
	                	fnCallback(null);
	            }
	        });
};

//自定义数据获取函数
var inspectRetrieveData = function( sSource, aoData, fnCallback ) {
	   aoData.push({'name':'beanProxy[clientId]','value':clientId});
	   aoData.push({'name':'beanProxy[loanId]','value':loanId});
	   aoData.push({'name':'beanProxy[enable]','value':0});
	   aoData.push({name:"v2hldghlcib0agugzgf0ysbhy2nlc3m",value:1});
	   aoData.push({name:"beanProxy[ownerType]",value:'SH'});
	        $.ajax( {
	                type: "POST", 
	                url: sSource, 
	                cache : false,
	                dataType : "json",
	                data : aoData, 
	                success: function(resp) {
	                	if(resp && resp.state == 200){
	                		fnCallback(resp.datagrid);
	                		return false;
	                	}
	                	fnCallback(null);
	            }
	        });
};

//修改电话调查信息
var updateLinkInfo = function(id){
	var aData = $('#linkTable').dataTable().fnGetData();
	$.each(aData,function(index,node){
		if(node.id==id){
			$('#linkForm').form('load',node);
			return;
		}
	});
	
};
//物理删除电话调查记录
var dropLinkInfo = function(id){
	$.dialog.confirm('你确定删除这条电话调查记录吗？', function(){
		$.ajax({
	       	url:'sys/LoanLink/drop',
	    	data:{pks:id},
	    	type:'post',
	    	dataType:'json',
	    	success:function(result){
	    	        if(result.state == "200"){
	    	        	$.dialog({
	    					icon: 'success.gif',
	    					title: '提示',
	    				    content: '删除成功！',
	    				    ok: function(){
	    				        this.close();
	    				    }
	    				});
	    	        	$('#linkTable').dataTable().fnDraw();
	    	        }else{
	    	        	$.dialog.alert('删除失败！');
	    	        }
	    		}
	        });
	}, function(){
//	    $.dialog.tips('执行取消操作');
	});
};


//修改信用信息
var updateCreditInfo = function(id){
	var aData = $('#creditTable').dataTable().fnGetData();
	$.each(aData,function(index,node){
		if(node.id==id){
			$('#creditForm').form('load',node);
			return false;
		}
	});
	
};

var dropCreditInfo = function(id){
	$.dialog.confirm('你确定删除这条信用调查记录吗？', function(){
		$.ajax({
	       	url:'sys/LoanCreditLog/drop',
	    	data:{pks:id},
	    	type:'post',
	    	dataType:'json',
	    	success:function(result){
	    	        if(result.state == "200"){
	    	        	$.dialog({
	    					icon: 'success.gif',
	    					title: '提示',
	    				    content: '删除成功！',
	    				    ok: function(){
	    				        this.close();
	    				    }
	    				});
	    	        	$('#creditTable').dataTable().fnDraw();
	    	        	cleanCreditForm();
	    	        }else{
	    	        	$.dialog.alert('删除失败！');
	    	        }
	    		}
	        });
	}, function(){
//	    $.dialog.tips('执行取消操作');
	});
};
//清空电话调查form表单
var cleanForm = function(){
	$("#linkForm").form()[0].reset();
	$("#linkId").val("");
	
};


//清空电话调查form表单
var cleanCreditForm = function(){
	$("#creditForm").form()[0].reset();
	$("#creditId").val("");
	
};

//退回调查
var returnLoan = function(){
	$.dialog.confirm('你确定退回这条申请单吗？', function(){
		$.ajax({
	       	url:'sys/LoanExt/back',
	    	data:{id:loanId,toStatus:1},
	    	type:'post',
	    	dataType:'json',
	    	success:function(result){
	    	        if(result.state == "200"){
	    	        	$.dialog({
	    					icon: 'success.gif',
	    					title: '提示',
	    				    content: '退回申请单成功！',
	    				    ok: function(){
	    				    	location.href = 'jsp/loan/auditLoanList.jsp';
	    				    }
	    				});
	    	        }else{
	    	        	$.dialog.alert('退回申请单失败！');
	    	        }
	    		}
	        });
	}, function(){
//	    $.dialog.tips('执行取消操作');
	});
};

//提交调查
var submitAudit = function(){
	$.ajax({
       	url:'sys/LoanExt/submitStatus',
    	data:{id:loanId,loanStatus:4,loanAuditorTime:top.nowTime,loanAuditorName:loginUser.userFullName,loanAuditor:loginUser.id,returnStatus:0},
    	type:'post',
    	dataType:'json',
    	success:function(result){
    	        if(result.state == "200"){
    	        	$.dialog({
    					icon: 'success.gif',
    					title: '提示',
    				    content: '提交审核成功！',
    				    ok: function(){
    				    	location.href = 'jsp/loan/auditLoanList.jsp';
    				    }
    				});
    	        }else{
    	        	$.dialog.alert('提交审核失败！');
    	        }
    		}
        });
};

//初始化考察人
var initAutoComplete = function(){

	$('input[name="inspectUserName"]').extraAutoComplete({
		 afterSelectedHandler: function(data){//选择数据之后的回调函数
			  $('#inspectUserId').val(data.id);
	        }
	});
	

};

var del_default = function(id){
	$.dialog.confirm('你确定删除这个附件吗？', function(){
		$.ajax({
	       	url:'sys/SysAccessory/delete',
	    	data:{pks:id},
	    	type:'post',
	    	dataType:'json',
	    	success:function(result){
	    	        if(result.state == "200"){
	    	        	$.dialog({
	    					icon: 'success.gif',
	    					title: '提示',
	    				    content: '删除成功！',
	    				    ok: function(){
	    				        this.close();
	    				    }
	    				});
	    	        	$('#inspectTable').dataTable().fnDraw();
	    	        }else{
	    	        	$.dialog.alert('删除失败！');
	    	        }
	    		}
	        });
	});
};

//init操作
$(function(){
	$('.tablelist tbody tr:odd').addClass('odd');
	$("#usual1 ul").idTabs();
	loanId = $('#loanId').val();
	clientId = $('#clientId').val();
	initForm();
	initFormData();
	initDataTable();
	initAutoComplete();
	
	$('#accessoryClass').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Accessory_Class_Audit_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#loanType').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Credit_Type_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#loanStatus').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Credit_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#insureStatus').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Insure_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#insureEi').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Insure_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#insureMi').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Insure_Mi_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#insureBi').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Insure_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#insureHi').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Insure_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#insureWi').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Insure_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#insureCi').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Insure_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#linkRelation').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Link_Relation_Type_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#linkSource').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Link_Source_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('#linkCallStatus').mSelect({
		myClass:'easyui-validatebox dfinput',
		width:192,
		baseCode:'Loan_Link_Call_Status_Code',
		isAllSelect:true,
		dataOptions:'required:true'
	});
	
	$('input[name="confirm_button"]').click(function(){
		$('#linkForm').submit();
	});
	
	//给贷款详情页面赋值
	var url = 'sys/Loan/findByPk?pks='+loanId;
	_set_default_lable_text(url,true);
});
